import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import Home from '@/views/home/index.vue'

// 关于
import AboutView from '../views/AboutView.vue'

// 登录
import login from '@/views/loginView.vue/index.vue'


// 底部导航
import footerView from '@/components/Footer/footerView.vue'

// 头部导航
import headerCom from '@/components/header/headerCom.vue'

// 设置密码
import setPassword from '@/views/setPassword/index.vue'

// 注册
import registerIndexView from '@/views/register/registerIndexView.vue'
import register1View from '@/views/register/register1View.vue'
import register2View from '@/views/register/register2View.vue'

// 发现页面
import findView from '@/views/findView/indexView.vue'

// 位置页面
import positionView from '@/views/positionView/index.vue'


// 选择城市
import selectCity from '@/views/selectCity/index.vue'
import eidicty from '@/views/selectCity/eidicty.vue'


// 看游记
import watchravelogues from '@/views/watchravelogues/index.vue'

// 必读榜
import MustReadListView from '@/views/MustReadListView/index.vue'

// 选酒店
import ChooseahotelView from '@/views/ChooseahotelView/index.vue'

// 找攻略
import FindaguideView from '@/views/FindaguideView/index.vue'


// 我的
import userView from '@/views/userView/index.vue'

// 设置
import setView from '@/views/setView/index.vue'

// 账户管理
import changePasswordView from '@/views/changePasswordView/index.vue'
import userGarnde from '@/views/changePasswordView/userGarnde.vue'
import changgeasswordView from '@/views/changePasswordView/changgeasswordView.vue'

// 编辑用户
import editUserView from '@/views/editUserView/index.vue'




const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      components: {
        default: Home,
        footerView
      },
      meta: {
        title: '关注'
      }
    },
    {
      path: '/about',
      name: 'about',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      components: {
        default: AboutView,
        footerView
      },
      meta: {
        title: '关于'
      }
    },

    // 登录
    {
      path: '/login',
      name: 'login',
      components: {
        default: login,
      },
      meta: {
        title: '登录'
      }
    },
    // 修改密码
    {
      path: '/setPassword',
      name: 'setPassword',
      components: {
        default: setPassword,
      },
      meta: {
        title: '密码设置'
      }
    },
    {
      path: '/registerIndexView',
      name: 'registerIndexView',
      redirect: '/registerIndexView/register1View',
      components: {
        default: registerIndexView,
      },
      meta: {
        title: '注册'
      },
      children: [
        {
          path: 'register1View',
          name: 'register1View',
          component: register1View
        },
        {
          path: 'register2View',
          name: 'register2View',
          component: register2View
        }
      ]
    },
    // 发现
    {
      path: '/findView',
      name: 'findView',
      components: {
        default: findView,
        footerView
      },
      meta: {
        title: '发现'
      }
    },
    // 位置页面
    {
      path: '/positionView',
      name: 'positionView',
      components: {
        default: positionView,
        footerView
      },
      meta: {
        title: '位置页面'
      }
    },
    // 关注页面
    {
      path: '/findView',
      name: 'findView',
      components: {
        default: findView,
        footerView
      },
      meta: {
        title: '发现'
      }
    },
    // 选城市
    {
      path: '/selectCity',
      name: 'selectCity',
      components: {
        default: selectCity,
      },
      meta: {
        title: '选城市'
      },

    },
    {
      path: '/eidicty',
      name: 'eidicty',
      components: {
        default: eidicty,
      },
      meta: {
        title: '景点详情'
      }
    },

    // 看游记
    {
      path: '/watchravelogues',
      name: 'watchravelogues',
      components: {
        default: watchravelogues,
      },
      meta: {
        title: '看游记'
      }
    },
    // 必读榜
    {
      path: '/MustReadListView',
      name: 'MustReadListView',
      components: {
        default: MustReadListView,
      },
      meta: {
        title: '必读榜'
      }
    },
    // 选酒店
    {
      path: '/ChooseahotelView',
      name: 'ChooseahotelView',
      components: {
        default: ChooseahotelView,
        footerView

      },
      meta: {
        title: '选酒店'
      }
    },
    // 找攻略
    {
      path: '/FindaguideView',
      name: 'FindaguideView',
      components: {
        default: FindaguideView,
      },
      meta: {
        title: '找攻略'
      }
    },
    // 我的
    {
      path: '/userView',
      name: 'userView',
      components: {
        default: userView,
        footerView
      },
      meta: {
        title: '我的'
      },

    },
    {
      path: '/editUserView',
      name: 'editUserView',
      components: {
        default: editUserView,
        footerView
      },
      meta: {
        title: '编辑用户'
      },

    },

    // 设置
    {
      path: '/setView',
      name: 'setView',
      components: {
        default: setView,
      },
      meta: {
        title: '设置'
      }
    },
    // 账户管理
    {
      path: '/changePasswordView',
      name: 'changePasswordView',
      components: {
        default: changePasswordView,
      },
      redirect: '/changePasswordView/userGarnde',
      meta: {
        title: '账户管理'
      },
      children: [
        {
          // 子路由path 里面不要加/
          path: 'userGarnde',
          name: 'userGarnde',
          components: {
            default: userGarnde,
          },
        },
        {
          // 子路由path 里面不要加/
          path: 'changgeasswordView',
          name: 'changgeasswordView',
          components: {
            default: changgeasswordView,
          },
        }

      ]

    }

  ],
})


// 全局后置守卫
router.afterEach((to, from) => {
  document.title = String(to.meta.title)
})

export default router
